<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Acknowledge the receipt of a message</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.amqpqueue.html">AMQPQueue</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="amqpqueue.bind.html">AMQPQueue::bind</a></div>
 <div class="up"><a href="class.amqpqueue.html">AMQPQueue</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="amqpqueue.ack" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">AMQPQueue::ack</h1>
  <p class="verinfo">(PECL amqp &gt;= Unknown)</p><p class="refpurpose"><span class="refname">AMQPQueue::ack</span> &mdash; <span class="dc-title">Acknowledge the receipt of a message</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-amqpqueue.ack-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>AMQPQueue::ack</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$delivery_tag</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code>AMQP_NOPARAM</code></strong></span></span>
  ] )</div>

  <p class="para rdfs-comment">
    This method allows the acknowledgement of a message that is retrieved without the <strong><code>AMQP_AUTOACK</code></strong> flag through
    <span class="methodname"><a href="amqpqueue.get.html" class="methodname">AMQPQueue::get()</a></span> or <span class="methodname"><a href="amqpqueue.consume.html" class="methodname">AMQPQueue::consume()</a></span>
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-amqpqueue.ack-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">delivery_tag</code></em></dt>

     <dd>

      <p class="para">
       The message delivery tag of which to acknowledge receipt.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">flags</code></em></dt>

     <dd>

      <p class="para">
       The only valid flag that can be passed is <strong><code>AMQP_MULTIPLE</code></strong>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-amqpqueue.ack-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <strong class="classname">AMQPChannelException</strong> if the channel is not open.
  </p>
  <p class="para">
   Throws <strong class="classname">AMQPConnectionException</strong> if the connection to the broker was lost.
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-amqpqueue.ack-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-amqpqueue.ack-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4109">
    <p><strong>Example #1 <span class="methodname"><strong>AMQPQueue::ack()</strong></span> example with <span class="methodname"><a href="amqpqueue.get.html" class="methodname">AMQPQueue::get()</a></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;a&nbsp;connection&nbsp;using&nbsp;all&nbsp;default&nbsp;credentials:&nbsp;*/<br /></span><span style="color: #0000BB">$connection&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">AMQPConnection</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$connection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">connect</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$channel&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">AMQPChannel</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;create&nbsp;a&nbsp;queue&nbsp;object&nbsp;*/<br /></span><span style="color: #0000BB">$queue&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">AMQPQueue</span><span style="color: #007700">(</span><span style="color: #0000BB">$channel</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//declare&nbsp;the&nbsp;queue<br /></span><span style="color: #0000BB">$queue</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">declare</span><span style="color: #007700">(</span><span style="color: #DD0000">'myqueue'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//get&nbsp;the&nbsp;next&nbsp;message,&nbsp;but&nbsp;don't&nbsp;mark&nbsp;it&nbsp;as&nbsp;delivered<br /></span><span style="color: #0000BB">$message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$queue</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #0000BB">AMQP_NOPARAM</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'msg'</span><span style="color: #007700">];<br /><br /></span><span style="color: #FF8000">//acknowledge&nbsp;the&nbsp;message&nbsp;as&nbsp;received<br /></span><span style="color: #0000BB">$queue</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ack</span><span style="color: #007700">(</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'delivery_tag'</span><span style="color: #007700">]);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-4110">
    <p><strong>Example #2 <span class="methodname"><strong>AMQPQueue::ack()</strong></span> example with <span class="methodname"><a href="amqpqueue.consume.html" class="methodname">AMQPQueue::consume()</a></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;a&nbsp;connection&nbsp;using&nbsp;all&nbsp;default&nbsp;credentials:&nbsp;*/<br /></span><span style="color: #0000BB">$connection&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">AMQPConnection</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$connection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">connect</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;create&nbsp;a&nbsp;queue&nbsp;object&nbsp;*/<br /></span><span style="color: #0000BB">$queue&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">AMQPQueue</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//declare&nbsp;the&nbsp;queue<br /></span><span style="color: #0000BB">$queue</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">declare</span><span style="color: #007700">(</span><span style="color: #DD0000">'myqueue'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'min'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'max'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'ack'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">false<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//get&nbsp;the&nbsp;messages,&nbsp;but&nbsp;don't&nbsp;mark&nbsp;them&nbsp;as&nbsp;delivered<br /></span><span style="color: #0000BB">$messages&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$queue</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">consume</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$messages&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'message_body'</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//acknowledge&nbsp;the&nbsp;message&nbsp;as&nbsp;received<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$queue</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ack</span><span style="color: #007700">(</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'delivery_tag'</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.amqpqueue.html">AMQPQueue</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="amqpqueue.bind.html">AMQPQueue::bind</a></div>
 <div class="up"><a href="class.amqpqueue.html">AMQPQueue</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
